package com.controller;

import com.aop.SystemLog;
import com.dao.MemberDao;
import com.dto.DTO;
import com.entity.Member;
import com.entity.Member;
import com.exception.CustomException;
import com.page.PageInfo;
import com.service.MemberService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller //@Controller注解是用spring容器生成 对象 默认对象名 memberController
@RequestMapping("/memberController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /memberController
public class MemberController {
	@Resource
    MemberDao memberDao;
	@Resource
	MemberService memberService;
	@RequestMapping("/getAllMember")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
	public DTO<Member> getAllMember(){
		System.out.println("周传奇查询全部社团");
		List<Member> members =  memberDao.getAllMembers();
		return new DTO<Member>(200, "周传奇全部社团",members);
	}

	@RequestMapping("/deleteMemberById/{aId}")
	@ResponseBody
	public DTO<Member> deleteMemberById(@PathVariable("aId") Integer aId) throws CustomException {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(aId+"删除社团");
		return memberService.deleteMemberById(aId);
	}

	@RequestMapping("/getMemberByPage")
	@ResponseBody
	@SystemLog(module = "社团管理",methods = "分页查询社团")
	public DTO<Member> getMemberByPage(PageInfo pageInfo){//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页查询社团");
		List<Member> members = memberDao.getMemberByPage(pageInfo);
		System.out.println("周传奇");
		return new DTO<Member>(200, "分页查询社团成功",members);
	}

	@RequestMapping("getMemberByMnoWithMAR/{mno}")
	@ResponseBody
	public DTO<Member> getMemberByMnoWithMAR(@PathVariable("mno") String mno){//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("按社团查看社团活动记录");
		Member member = memberDao.getMemberByMnoWithMAR( mno );
		return new DTO<Member>(200, "按社团查看社团活动记录成功",null,member);
	}

	@RequestMapping("/getMemberByMnoWithMARAndAT/{mno}")
	@ResponseBody
	public DTO<Member> getMemberByMnoWithMARAndAT(@PathVariable("mno") String mno){//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("按社团查看社团活动记录附带活动");
		Member member = memberDao.getMemberByMnoWithMARAndAT( mno );
		return new DTO<Member>(200, "按社团查看社团活动记录附带活动成功",null,member);
	}

	@RequestMapping("/updateMememberTest")
	@ResponseBody
	public DTO<Member> updateMememberTest(Member member) throws CustomException {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("按社团查看社团活动记录附带活动");
		return memberService.updateMememberTest(member);
	}
	@RequestMapping("/addMember")
	@ResponseBody
	public DTO<Member> addMember(@RequestBody Member member) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加社团");
		System.out.println(member);
		return memberService.addMember(member);
	}
	@RequestMapping("/updateMemember")
	@ResponseBody
	public DTO<Member> updateMemember(@RequestBody Member member) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改社团");
		return memberService.updateMember(member);
	}

}
